package net.wangds.imagecomp.comp;

import java.awt.*;
import java.util.function.Consumer;

@FunctionalInterface
public interface DrawOperate extends Consumer<Graphics> {

   default void accept(Graphics gra){
       if(gra==null){
           return;
       }

       Graphics2D g = (Graphics2D)gra.create();
       try{
           drawing(g);
       }finally {
           g.dispose();
       }
   }

   void drawing(Graphics2D g);

   static void draw(Graphics g, Consumer<Graphics2D> callback){
       ((DrawOperate)(_g)->callback.accept(_g)).accept(g);
   }

}
